$("#keyword").on("keyup", function (event) {
    if (event.keyCode == 13) {
        curEl.bootstrapTable("refresh");
    }
});

$("#add").on("click", function () {
    $.showPage("", "新增", webRoot + "/console/systemModules/add.html?parent=0");
});

function initChild(index, row, $detail) {
    var $el = $detail.html('<table></table>').find('table');
    $el.addClass("child");
    $el.initTable({
        url: webRoot + '/console/systemModules/' + row.id + '/child',
        columns: systemChildModuleColumns(),
        height: null,
        buttons: [{
            id: "edit",
            btnClass: "btn btn-default btn-xs purple",
            icon: "fa fa-edit",
            name: "编辑",
            handler: function (event) {
                var curTarget = $el.bootstrapTable('getRowByUniqueId', $(event.currentTarget).attr("dataId"));
                $.showPage("", "编辑", webRoot + "/console/systemModules/edit.html?id=" + curTarget.id);
            }
        }]
    });
}

var curEl = $("#systemModulesTable");
curEl.initTable({
    url: webRoot + '/console/systemModules/parent',
    columns: systemParentModuleColumns(),
    isPagination: true,
    detailView: true,
    onExpandRow: function (index, row, $detail) {
        initChild(index, row, $detail);
    },
    buttons: [{
        id: "edit",
        btnClass: "btn btn-default btn-xs purple",
        icon: "fa fa-edit",
        name: "编辑",
        handler: function (row) {
            $.showPage("", "编辑", webRoot + "/console/systemModules/edit.html?id=" + row.id);
        }
    }, {
        id: "add",
        btnClass: "btn btn-default btn-xs purple",
        icon: "fa fa-edit",
        name: "新增子模块",
        handler: function (row) {
            $.showPage("", "新增子模块", webRoot + "/console/systemModules/add.html?parent=" + row.id);
        }
    }]
});